<?php

namespace App\Http\Requests\Api;

class CompanyDepartmentRequest extends ApiRequest
{
    public function rules()
    {
        return [
            'id' => $this->is('*/update') ? 'bail|required|integer' : '',
            'com_id' => $this->is('*/update') ? '' : 'bail|required|integer',
            'name' => 'required',
            'contacts' => 'required',
            'mobile' => 'bail|required_without:phone|mobile_verification',
            'phone' => 'bail|required_without:mobile|check_company_phone',
            'fax' => 'check_fax',
            'email' => 'email',
        ];
    }

    public function attributes()
    {
        return [
            'name' => '部门名称',
            'contacts' => '联系人',
            'mobile' => '手机',
            'phone' => '座机电话',
            'fax' => '传真',
            'email' => '电子邮件',
        ];
    }

    public function messages()
    {
        return array_merge(parent::messages(),[
            'mobile.required_without' => '固定电话与手机号码必须填写一项',
            'mobile.mobile_verification'=>'请输入正确的手机号码',
            'phone.required_without' => '固定电话与手机号码必须填写一项',
            'phone.check_company_phone'=>'请输入正确的区号和电话号码',
            'fax.check_fax'=>'请输入正确的传真号码',
        ]);
    }
}
